package com.cqh.dao.impl;

import com.cqh.bean.Grade;
import com.cqh.bean.Student;
import com.cqh.dao.DBUtils;
import com.cqh.dao.GradeDao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtils implements GradeDao {
    @Override
    public List<Grade> getGradeList() {
        List gradeList = new ArrayList();
        String sql = "select * from grade";
        try {
            ResultSet resultSet = query(sql, null);
            while (resultSet.next()){
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeid"));
                grade.setGradeName(resultSet.getString("gradename"));
//                grade.setStudentList((List<Student>) resultSet.getObject("studentList"));
                gradeList.add(grade);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return gradeList;
    }
}
